﻿<MContainer Fluid>
    <MRow>
        <MCol
            Cols="12"
            Sm="6">
            <MTextField
                @bind-Value="hintText"
                AppendIcon="@(show1 ? "mdi-eye" : "mdi-eye-off")"
                Rules="RequiredAndMinRule"
                Type="@(show1 ? "text" : "password")"
                Name="input-10-1"
                Label="Normal with hint text"
                Hint="At least 8 characters"
                Counter="true"
                OnAppendClick="() => show1 = !show1">
            </MTextField>
        </MCol>

        <MCol
            Cols="12"
            Sm="6">
            <MTextField
                AppendIcon="@(show2 ? "mdi-eye" : "mdi-eye-off")"
                Rules="RequiredAndMinRule"
                Type="@(show2 ? "text" : "password")"
                Name="input-10-2"
                Label="Visible"
                Hint="At least 8 characters"
                TValue="string"
                @bind-Value="@visible"
                Class="input-group--focused"
                OnAppendClick="() => show2 = !show2">
            </MTextField>
        </MCol>

        <MCol
            Cols="12"
            Sm="6">
            <MTextField
                AppendIcon="@(show3 ? "mdi-eye" : "mdi-eye-off")"
                Rules="RequiredAndMinRule"
                Type="@(show3 ? "text" : "password")"
                Name="input-10-2"
                Label="Not visible"
                Hint="At least 8 characters"
                @bind-Value="@notVisible"
                Class="input-group--focused"
                OnAppendClick="() => show3 = !show3">
            </MTextField>
        </MCol>

        <MCol
            Cols="12"
            Sm="6">
            <MTextField
                AppendIcon="@(show4 ? "mdi-eye" : "mdi-eye-off")"
                Rules="RequiredAndEmailMatchRule"
                Type="@(show4 ? "text" : "password")"
                Name="input-10-2"
                Label="Error"
                Hint="At least 8 characters"
                @bind-Value="@error"
                Error
                OnAppendClick="() => show4 = !show4">
            </MTextField>
        </MCol>
    </MRow>
</MContainer>

@code {

    private bool show1;
    private bool show2 = true;
    private bool show3;
    private bool show4;

    private string hintText = "Password";
    private string visible = "visible";
    private string notVisible = "no visible";
    private string error = "error";

    private Func<string, StringBoolean> RequiredRule => val => string.IsNullOrEmpty(val) ? "Required." : true;
    private Func<string, StringBoolean> MinRule => val => val.Length >= 8 ? true : "Min 8 characters";
    private Func<string, StringBoolean> EmailMatchRule => val => "The email and password you entered don't match";

    private IEnumerable<Func<string, StringBoolean>> RequiredAndMinRule => new List<Func<string, StringBoolean>>()
    {
        RequiredRule,
        MinRule
    };

    private IEnumerable<Func<string, StringBoolean>> RequiredAndEmailMatchRule => new List<Func<string, StringBoolean>>()
    {
        RequiredRule,
        EmailMatchRule
    };

}
